package com.four.reimbursemanage.controller;

import com.four.reimbursemanage.common.bean.ResponseData;
import com.four.reimbursemanage.common.controller.BaseController;
import com.four.reimbursemanage.dao.WorkapplyMapper;
import com.four.reimbursemanage.entity.OutmoneyApply;
import com.four.reimbursemanage.entity.Payapply;
import com.four.reimbursemanage.entity.Workapply;
import com.four.reimbursemanage.service.WorkapplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@CrossOrigin
@RequestMapping("/workapply")
public class WorkapplyController extends BaseController {
    @Autowired
    WorkapplyMapper workapplyMapper;
    @Autowired
    private WorkapplyService workapplyService;
    /**
     * 查询加班补助申请列表
     */
    @GetMapping("/workapplyList")
    public ResponseData<Object> getOutmoneyApply(
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize,
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "month",required = false)@DateTimeFormat(pattern = "yyyy-MM-dd")Date month,
            @RequestParam(value = "state",required = false) Integer state
    ){

        return returnObject(workapplyService.getOnrePage(pageNum,pageSize, name, month, state));
    }

    /**
     * 查询加班补助申请列表
     */

    @GetMapping("/selectByNum")
    public ResponseData<Object> getOutmoneyApplyUser(
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize,
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "month",required = false)@DateTimeFormat(pattern = "yyyy-MM-dd")Date month,
            @RequestParam(value = "state",required = false) Integer state,
            @RequestParam(value = "number",required = false) String number
    ){

        return returnObject(workapplyService.getOnrePageUser(pageNum,pageSize, name, month, state, number));
    }

    /**
     * 新增加班补助申请
     */
    @PostMapping("/add")
    public ResponseData<Boolean> add(Workapply workapply)
    {
        return returnBoolean(workapplyService.insertWorkapply(workapply));
    }

    /**
     * 修改加班补助申请
     */

    @PutMapping("/update")
    public ResponseData<Boolean> edit(@RequestBody Workapply workapply)
    {
        System.out.println(workapply.getId());
        return returnBoolean(workapplyService.updateWorkapply(workapply));
    }

    @PutMapping("/updateC")
    public ResponseData<Boolean> updateS(@RequestBody Workapply workapply)
    {
        return returnBoolean(workapplyService.updateC(workapply));
    }
}
